function isBetween(t, start, end) {
  return t >= start && t <= end
}
function getBloodPressureStatus(high, low) {
  var text
  var status
  if (isBetween(high, 120, 139) || isBetween(low, 80, 89) ) {
    text = '正常'
    status = 1
  }
  if (isBetween(high, 140, 159) || isBetween(low, 90, 99)) {
    text = '轻度偏高'
    status = 2
  }
  if (isBetween(high, 160, 179) || isBetween(low, 100, 109)) {
    text = '中度偏高'
    status = 3
  }
  if (high > 180 || low > 110) {
    text = '重度偏高'
    status = 4
  }
  if (high < 120 || low < 80) {
    text = '正常'
    status = 1
  }

  return {
    text: '血压趋势' + text,
    status: status
  }
}

function formatTime(date) {
  return date.slice(date.indexOf(' '))
}

function getHeartStatus(num) {
  var text, status = 0
  if (num < 50) {
    text = '偏低'
  } else if (num <= 100) {
    text = '正常'
    status = 1
  } else {
    text = '偏高'
    status = 2
  }

  return {
    text: '心率趋势' + text,
    status: status
  }
}

function getBloodOxygenStatus(num) {
  var text, status = 0
  if (num < 93) {
    text = '偏低'
  } else {
    text = '正常'
    status = 1
  }

  return {
    text: '血氧趋势' + text,
    status: status
  }
}

function getTemperatureStatus(num) {
  var text, status = 0
  if (num <= 36) {
    text = '偏低'
  } else if (num > 36 && num <= 37) {
    text = '正常'
    status = 1
  } else {
    text = '偏高'
    status = 2
  }

  return {
    text: '体温趋势' + text,
    status: status
  }
}

module.exports = {
  getBloodPressureStatus: getBloodPressureStatus,
  formatTime: formatTime,
  getHeartStatus: getHeartStatus,
  getBloodOxygenStatus: getBloodOxygenStatus,
  getTemperatureStatus: getTemperatureStatus
}
